package com.xiaozhengkeji.colastartboot.api;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
import com.xiaozhengkeji.colastartboot.annotation.IPFlowValve;
import com.xiaozhengkeji.colastartboot.base.entitys.SystemUser;
import com.xiaozhengkeji.colastartboot.base.services.SystemUserService;
import com.xiaozhengkeji.colastartboot.bean.ResponseBean;
import com.xiaozhengkeji.colastartboot.bean.type.ResCodeType;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.LinkedList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/cloud/v1/gamesense")
public class GameSenseCloudApi {

    SystemUserService systemUserService;

    @Autowired
    public GameSenseCloudApi(SystemUserService systemUserService) {
        this.systemUserService = systemUserService;
    }

    /**
     * 下载专属load
     */
    @ApiOperation("下载专属Load")
    @GetMapping("download/{Token}")
    @IPFlowValve(urlLogo = "download", limit = 5, time = 60, message = "请勿连续下载")
    public void download(@PathVariable("Token") String Token,
                         HttpServletResponse response) {
        if (StpUtil.getLoginIdByToken(Token) == null) {
            response.setStatus(401);
            return;
        }

        Integer loginID = Integer.parseInt((String) StpUtil.getLoginIdByToken(Token));
        SystemUser userEntity = systemUserService.selectByPrimaryKey(loginID);
        /*生成专属load*/
    }

    /**
     * 初次验证
     */
    @ApiOperation("初次验证")
    @PostMapping("toVerify")
    @IPFlowValve(urlLogo = "download", limit = 5, time = 60, message = "非法破解")
    public ResponseBean toVerify(@ApiParam("用户加载器Token") @RequestParam("userToken") String userToken,
                                 @ApiParam("用户HWID") @RequestParam("userHWID") String userHWID,
                                 @ApiParam("用户Steam") @RequestParam("userSteam") String userSteam,
                                 @ApiParam("用户HWIDSig") @RequestParam("userHWIDSig") String userHWIDSig) {
        List<String> luaList = new LinkedList<>();
        for (int i = 0; i < 10; i++) {
            luaList.add(IdUtil.randomUUID());
        }
        return new ResponseBean(ResCodeType.Success, "欢迎您: 管理员(as作者)", luaList, IdUtil.randomUUID());
    }
}
